package com.qlzb.taskmanagement.pojo;

/**
 * Created with IntelliJ IDEA.
 *
 * @ClassName outputWrapper
 * @Description  TODO   结果信息，统一数据返回格式
 * @Authr 袁聪
 * @Date 2018/6/1 16:05
 * @Version v2.0
 */
public class OutputWrapper {

    // 是否成功
    private boolean success;
    // 状态码
    private String code;
    // 返回信息
    private String message;
    // 返回数据
    private Object data;



    /**
     * 自定义返回结果
     * 建议使用统一的返回结果，特殊情况可以使用此方法
     * @param success
     * @param code
     * @param message
     * @param data
     * @return
     */
    public static OutputWrapper markCustom(boolean success, String code, String message, Object data){
        OutputWrapper outputWrapper = new OutputWrapper();
        outputWrapper.setSuccess(success);
        outputWrapper.setCode(code);
        outputWrapper.setMessage(message);
        outputWrapper.setData(data);
        return outputWrapper;
    }

    public static OutputWrapper markSuccess(String message, Object data){
        OutputWrapper outputWrapper = new OutputWrapper();
        outputWrapper.setSuccess(true);
        outputWrapper.setCode(ReturnCode.EDIT_SUCCESS.getCode());
        outputWrapper.setMessage(message);
        outputWrapper.setData(data);
        return outputWrapper;
    }

    public static OutputWrapper markError( String message){
        OutputWrapper outputWrapper = new OutputWrapper();
        outputWrapper.setSuccess(false);
        outputWrapper.setCode(ReturnCode.EDIT_ERROR.getCode());
        outputWrapper.setMessage(message);
        outputWrapper.setData(null);
        return outputWrapper;
    }

    /**
     * 参数为空或者参数格式错误
     * @param data  错误信息
     * @return
     */
    public static OutputWrapper markParamError(Object data){
        OutputWrapper outputWrapper = new OutputWrapper();
        outputWrapper.setSuccess(false);
        outputWrapper.setCode(ReturnCode.PARAMS_ERROR.getCode());
        outputWrapper.setMessage(ReturnCode.PARAMS_ERROR.getMessage());
        outputWrapper.setData(data);
        return outputWrapper;
    }

    /**
     * 参数是正确的
     * @return
     */
    public static OutputWrapper markParamRight(){
        OutputWrapper outputWrapper = new OutputWrapper();
        outputWrapper.setSuccess(true);
        outputWrapper.setCode(ReturnCode.PARAMS_RIGHT.getCode());
        outputWrapper.setMessage(ReturnCode.PARAMS_RIGHT.getMessage());
        outputWrapper.setData(null);
        return outputWrapper;
    }


    /**
     * 查询失败
     * @return
     */
    public static OutputWrapper markError(){
        OutputWrapper outputWrapper = new OutputWrapper();
        outputWrapper.setSuccess(false);
        outputWrapper.setCode(ReturnCode.FEAILED.getCode());
        outputWrapper.setMessage(ReturnCode.FEAILED.getMessage());
        outputWrapper.setData(null);
        return outputWrapper;
    }

    /**
     * 查询成功但无数据
     * @return
     */
    public static OutputWrapper markSuccessButNoData(){
        OutputWrapper outputWrapper  = new OutputWrapper();
        outputWrapper.setSuccess(true);
        outputWrapper.setCode(ReturnCode.NODATA.getCode());
        outputWrapper.setMessage(ReturnCode.NODATA.getMessage());
        outputWrapper.setData(null);
        return outputWrapper;
    }

    /**
     * 查询成功且有数据
     * @param data
     * @return
     */
    public static OutputWrapper markSuccess(Object data){
        OutputWrapper outputWrapper = new OutputWrapper();
        outputWrapper.setSuccess(true);
        outputWrapper.setCode(ReturnCode.SUCCESS.getCode());
        outputWrapper.setMessage(ReturnCode.SUCCESS.getMessage());
        outputWrapper.setData(data);
        return  outputWrapper;
    }


//---------------------------- 数据库 增删改查 start (Service层返回结果) --------------------------------------

    /**
     * 查询数据成功
     * @return
     */
    public static OutputWrapper markSelectSuccess(Object o){
        OutputWrapper outputWrapper = new OutputWrapper();
        outputWrapper.setSuccess(true);
        outputWrapper.setCode(ReturnCode.FIND_SUCCESS.getCode());
        outputWrapper.setMessage(ReturnCode.FIND_SUCCESS.getMessage());
        outputWrapper.setData(o);
        return outputWrapper;
    }

    /**
     * 查询数据成功，但无数据
     * @return
     */
    public static OutputWrapper markSelectSuccessNoData(){
        OutputWrapper outputWrapper = new OutputWrapper();
        outputWrapper.setSuccess(true);
        outputWrapper.setCode(ReturnCode.FIND_SUCCESS_NO_DATA.getCode());
        outputWrapper.setMessage(ReturnCode.FIND_SUCCESS_NO_DATA.getMessage());
        outputWrapper.setData(null);
        return outputWrapper;
    }


    /**
     * 查询数据失败
     * @return
     */
    public static OutputWrapper markSelectError(){
        OutputWrapper outputWrapper = new OutputWrapper();
        outputWrapper.setSuccess(false);
        outputWrapper.setCode(ReturnCode.FIND_ERROR.getCode());
        outputWrapper.setMessage(ReturnCode.FIND_ERROR.getMessage());
        outputWrapper.setData(null);
        return outputWrapper;
    }

    /**
     * 添加数据成功
     * @return
     */
    public static OutputWrapper markInsertSuccess(Object o){
        OutputWrapper outputWrapper = new OutputWrapper();
        outputWrapper.setSuccess(true);
        outputWrapper.setCode(ReturnCode.ADD_SUCCESS.getCode());
        outputWrapper.setMessage(ReturnCode.ADD_SUCCESS.getMessage());
        outputWrapper.setData(o);
        return outputWrapper;
    }

    /**
     * 添加数据失败
     * @return
     */
    public static OutputWrapper markInsertError(){
        OutputWrapper outputWrapper = new OutputWrapper();
        outputWrapper.setSuccess(false);
        outputWrapper.setCode(ReturnCode.ADD_ERROR.getCode());
        outputWrapper.setMessage(ReturnCode.ADD_ERROR.getMessage());
        outputWrapper.setData(null);
        return outputWrapper;
    }

    /**
     * 修改数据成功
     * @return
     */
    public static OutputWrapper markUpdateSuccess(Object o){
        OutputWrapper outputWrapper = new OutputWrapper();
        outputWrapper.setSuccess(true);
        outputWrapper.setCode(ReturnCode.EDIT_SUCCESS.getCode());
        outputWrapper.setMessage(ReturnCode.EDIT_SUCCESS.getMessage());
        outputWrapper.setData(o);
        return outputWrapper;
    }

    /**
     * 修改数据失败
     * @return
     */
    public static OutputWrapper markUpdateError(){
        OutputWrapper outputWrapper = new OutputWrapper();
        outputWrapper.setSuccess(false);
        outputWrapper.setCode(ReturnCode.EDIT_ERROR.getCode());
        outputWrapper.setMessage(ReturnCode.EDIT_ERROR.getMessage());
        outputWrapper.setData(null);
        return outputWrapper;
    }

    /**
     * 删除数据成功
     * @return
     */
    public static OutputWrapper markDeleteSuccess(Object o){
        OutputWrapper outputWrapper = new OutputWrapper();
        outputWrapper.setSuccess(true);
        outputWrapper.setCode(ReturnCode.DELETE_SUCCESS.getCode());
        outputWrapper.setMessage(ReturnCode.DELETE_SUCCESS.getMessage());
        outputWrapper.setData(o);
        return outputWrapper;
    }

    /**
     * 删除数据失败
     * @return
     */
    public static OutputWrapper markDeleteError(){
        OutputWrapper outputWrapper = new OutputWrapper();
        outputWrapper.setSuccess(false);
        outputWrapper.setCode(ReturnCode.DELETE_ERROR.getCode());
        outputWrapper.setMessage(ReturnCode.DELETE_ERROR.getMessage());
        outputWrapper.setData(null);
        return outputWrapper;
    }

//---------------------------- 数据库 增删改查 end --------------------------------------



    //---------------------------- 登录 start --------------------------------------、

    /**
     * 登录成功
     * @return
     */
    public static OutputWrapper markLoginSuccess(Object o){
        OutputWrapper outputWrapper = new OutputWrapper();
        outputWrapper.setSuccess(true);
        outputWrapper.setCode(ReturnCode.LOGIN_SUCCESS.getCode());
        outputWrapper.setMessage(ReturnCode.LOGIN_SUCCESS.getMessage());
        outputWrapper.setData(o);
        return outputWrapper;
    }

    /**
     * 登录失败
     * @return
     */
    public static OutputWrapper markLoginError(){
        OutputWrapper outputWrapper = new OutputWrapper();
        outputWrapper.setSuccess(false);
        outputWrapper.setCode(ReturnCode.LOGIN_ERROR.getCode());
        outputWrapper.setMessage(ReturnCode.LOGIN_ERROR.getMessage());
        outputWrapper.setData(null);
        return outputWrapper;
    }



    /**
     * 登录失效
     * @return
     */
    public static OutputWrapper markLoginFailure(){
        OutputWrapper outputWrapper = new OutputWrapper();
        outputWrapper.setSuccess(false);
        outputWrapper.setCode(ReturnCode.LOGIN_FAILURE.getCode());
        outputWrapper.setMessage(ReturnCode.LOGIN_FAILURE.getMessage());
        outputWrapper.setData(null);
        return outputWrapper;
    }


    /**
     * 未登录
     * @return
     */
    public static OutputWrapper markNotLogin(){
        OutputWrapper outputWrapper = new OutputWrapper();
        outputWrapper.setSuccess(false);
        outputWrapper.setCode(ReturnCode.NOT_LOGIN.getCode());
        outputWrapper.setMessage(ReturnCode.NOT_LOGIN.getMessage());
        outputWrapper.setData(null);
        return outputWrapper;
    }








//---------------------------- 登录 end --------------------------------------




    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "outputWrapper{" +
                "success=" + success +
                ", code='" + code + '\'' +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
